package com.tanhua.manager.listeners;

import com.tanhua.autoconfig.properties.HuaWeiUGCProperties;
import com.tanhua.autoconfig.templates.HuaWeiUGCTemplate;
import com.tanhua.domain.db.Log;
import com.tanhua.domain.mongo.Movement;
import com.tanhua.dubbo.api.mongo.MovementApi;
import com.tanhua.manager.service.LogService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(topic = "movement_huawei_check",consumerGroup = "huaweiCheckGroup")
public class MovementStateListener implements RocketMQListener<String> {

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;
    @Reference
    private MovementApi movementApi;

    @Override
    public void onMessage(String movementId) {
//        获取动态的图片和内容
        Movement movement = movementApi.queryMovementById(movementId);
        if(movement==null){
            return;
        }

        if(movement.getState()!=0){ //此动态已审核
            return;
        }

       boolean textCheck = huaWeiUGCTemplate.textContentCheck(movement.getTextContent());
       boolean imageCheck =  huaWeiUGCTemplate.imageContentCheck(movement.getMedias().toArray(new String[]{}));

       Integer state = 1;
       if(textCheck&&imageCheck){
//         修改动态的状态state=1   sql: update biaomiao set state=? where id=movementId
       }else{
           state = 2;
//           修改动态的状态state=2
//           movementApi.updateStateById(movementId,2);
       }
        movementApi.updateStateById(movementId,state);

        System.out.println("动态已经审核完成.............");
    }
}
